<html xmlns="http://www.w3.org/1999/xhtml"  
      xmlns:h="http://java.sun.com/jsf/html"  
      xmlns:f="http://java.sun.com/jsf/core"  
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:pe="http://primefaces.org/ui/extensions"> 

    <ui:composition template="../index.xhtml">
        <ui:define name="conteudo">
            <!--**************************************************************-->
            <!--                       TABELA DE VENDAS                       -->
            <!--**************************************************************-->
            <h:form>
                <p:messages id="mensagens"/>
                <p:dataTable id="multiCars" var="car" value="#{vendaControler.listVendaCabecalho}" paginator="true" rows="10"  
                             selection="#{vendaControler.listVendaCabecalhoSelecionados}" rowKey="#{car.id}" emptyMessage="Nenhum registro encontrado."
                             rowsPerPageTemplate="5,10,15,#{vendaControler.listVendaCabecalho.size()}">  
                    <f:facet name="header" >  
                        Checkbox Based Selection  
                        <p:commandButton action="#{vendaControler.emitirNF_e()}" update=":FormItens @form" value="Emitir NF-e" onclick="statusDialog.show();" onsuccess="statusDialog.hide();"/> 
                        <p:commandButton action="#{vendaControler.pegaItemSelecionado()}" update=":FormItens @form" value="Ver Itens"/> 
                    </f:facet>  

                    <!--                    <p:column selectionMode="single" style="width:18px" />  -->
                    <!--                    <p:ajax event="rowSelect" update="form:txtAccount"/>-->
                    <p:column selectionMode="multiple" style="width:18px" />  

                    <p:column headerText="Código " style="width: 80px;" sortBy="#{car.id}" filterBy="#{car.id}">  
                        #{car.id}  
                    </p:column>  

                    <p:column headerText="Cliente" sortBy="#{car.cliente.nome}"  filterBy="#{car.cliente.nome}">  
                        <p:commandLink id="ajax" update=":FormItens @form" actionListener="#{vendaControler.pegaItemSelecionado()}" style="margin-right:20px;">  
                            #{car.cliente.nome} 
                        </p:commandLink>
                    </p:column>  

                    <p:column headerText="Data venda" style="width: 90px;" sortBy="#{car.dataVenda}" filterBy="#{car.dataVenda}">
                        <h:outputText value="#{car.dataVenda}">
                            <f:convertDateTime /> 
                        </h:outputText>  
                    </p:column>  

                    <p:column headerText="Valor" style="width: 100px;" sortBy="#{car.valorVenda}" filterBy="#{car.valorVenda}">  
                        <h:outputText  value="#{car.valorVenda}">
                            <f:convertNumber type="currency"/>
                        </h:outputText>
                    </p:column> 

                    <p:column headerText="Caixa" style="width: 100px;" sortBy="#{car.idEcfMovimento.caixa.nome}" filterBy="#{car.idEcfMovimento.caixa.nome}">  
                        #{car.idEcfMovimento.caixa.nome}  
                    </p:column> 

                    <p:column headerText="Nf-e" style="width: 100px;" sortBy="#{car.possui_nfe}" filterBy="#{car.possui_nfe}">  
                        #{car.possui_nfe}  
                    </p:column> 
                </p:dataTable>
            </h:form>

            <p:dialog appendToBody="true" widgetVar="ItensVenda" modal="true" width="800" header="Itens da venda" resizable="false">
                <h:form id="FormItens" >  
                    <p:dataTable var="item" value="#{vendaControler.vendaCabecalho.vendaDetalheList}" paginator="true" rows="10" rowsPerPageTemplate="5,10,15">  
                        <p:column headerText="Codigo produto" sortBy="#{item.produto.gtin}" filterBy="#{item.produto.gtin}">  
                            <h:outputText value="#{item.produto.gtin}" />  
                        </p:column>  

                        <p:column headerText="Produto" sortBy="#{item.produto.descricao}" filterBy="#{item.produto.descricao}">  
                            <h:outputText value="#{item.produto.descricao}" />  
                        </p:column>  

                        <p:column headerText="Quantidade" sortBy="#{item.quantidade}" filterBy="#{item.quantidade}">  
                            <h:outputText value="#{item.quantidade}" />  
                        </p:column>  

                        <p:column headerText="Vlr.Unitário" sortBy="#{item.valorUnitario}" filterBy="#{item.valorUnitario}">  
                            <h:outputText value="#{item.valorUnitario}" >
                                <f:convertNumber type="currency"/>
                            </h:outputText> 
                        </p:column>  

                        <p:column headerText="Valor total" sortBy="#{item.valorTotal}" filterBy="#{item.valorTotal}">  
                            <h:outputText value="#{item.valorTotal}" >
                                <f:convertNumber type="currency"/>
                            </h:outputText> 
                        </p:column>  
                    </p:dataTable>  
                </h:form>  
            </p:dialog>
        </ui:define>
    </ui:composition>
</html>